using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NTTHAO.Web.BL.Authentication;

public partial class Sites_Vigor_Webparts_User_CheckAccount : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            string action = Request.QueryString["action"];
            string value = Request.QueryString["value"];

            string errorMessage = string.Empty;
            bool serviceOK = true;
            string serviceResult = string.Empty;

            if ("userid".Equals(action, StringComparison.OrdinalIgnoreCase))
            {
                User user = new User(value.Trim());
                if (user.ID > 0)
                {
                    serviceResult = "{\"existing\":1,\"userid\":\"" + user.UserName +"\"}";
                }
                else
                {
                    serviceResult = "{\"existing\":0,\"userid\":\"\"}";
                }
            }
            else if ("email".Equals(action, StringComparison.OrdinalIgnoreCase))
            {
                User user = User.GetUser(value.Trim());
                if (user != null)
                {
                    serviceResult = "{\"existing\":1,\"userid\":\"" + user.UserName + "\"}";
                }
                else
                {
                    serviceResult = "{\"existing\":0,\"userid\":\"\"}";
                }
            }
            else
            {
                serviceOK = false;
                errorMessage = "Invalid operation.";
            }

            string jsonResult = "{}";
            if (serviceOK)
            {
                jsonResult = "{\"result\":\"OK\", \"message\":\"" + errorMessage + "\", \"data\":" + serviceResult + "}";
            }
            else
            {
                jsonResult = "{\"result\":\"NG\", \"message\":\"" + errorMessage + "\", \"data\":" + serviceResult + "}";
            }

            Response.ClearContent();
            Response.HeaderEncoding = System.Text.Encoding.UTF8;
            Response.ContentType = "text/html";
            Response.Write(jsonResult);
        }
        catch { }
    }
}
